﻿using ServerFramework.Tools;

namespace ServerFramework.Net.Tcp
{
    public class RpcClient : Rpc
    {
        protected TcpClient _client;

        public RpcClient()
        {
            _client = new TcpClient();
            _client.onRecvMessage += RpcRecv;
        }

         /// <summary>
         /// 开始连接
         /// </summary>
         /// <param name="host"></param>
         /// <param name="port"></param>
         public bool Connect(string host, int port)
         {
             return _client.Connect(host, port);
         }

         protected override void RpcSend(ISender sender, RpcRequst requst)
         {
             if (_client != null)
             {
                 _client.Send(requst.Pack());
             }
             else
             {
                 Log.WriteLog(ELogLevel.LOG_ERROR, "client is null");
             }
         }
         public void Close(string errorMsg)
         {
             if (_client != null)
             {
                 _client.Close(errorMsg);
             }
         }
    }
}
